package xyz.yzy.coc.myqqrobot.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.forte.qqrobot.beans.messages.msgget.GroupMsg;
import com.forte.qqrobot.component.forlemoc.LemocApplication;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;
import xyz.yzy.coc.myqqrobot.entity.QqRecord;
import xyz.yzy.coc.myqqrobot.qqrebot.MyqqRobot;
import xyz.yzy.coc.myqqrobot.service.QqRecordService;
@Controller
@RequestMapping(value = "/qq")
public class QqRecordController {
	@Autowired
	private QqRecordService service;
	
	@RequestMapping(value="/toqqrecord")
	private String QqRecord(ModelMap map) {
		Order order=new Order(Direction.fromString("DESC"), "id");
		Sort sort=Sort.by(order);
		List<QqRecord> qqrecord =service.findAll(sort);
		map.put("qq", qqrecord);
		return "qq/qqrecord";
	}
	@RequestMapping(value = "/torebot")
	@ResponseBody
	private void torebot() {
		 
		new LemocApplication().run(new MyqqRobot());
	}
	
	public void tosave(GroupMsg msg) {
		QqRecord qqentity = new QqRecord();
		qqentity.setMsg(msg.getMsg());
		qqentity.setQqnumber(msg.getGroup());
		qqentity.setQunnumber(msg.getQQ());
		qqentity.setType(msg.getFont());
		qqentity.setTime(msg.getTime());
		service.save(qqentity);
	}
}
